/**
 * Created by Administrator on 2017-04-05.
 */
var alipayurl=""
////获取url中的参数
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return r[2]; return null; //返回参数值
}
/**
 * 格式化日期
 * @param fmt
 * @returns {*}
 * @constructor
 */
Date.prototype.Format = function(fmt)
{ //author: meizz
    var o = {
        "M+" : this.getMonth()+1,                 //月份
        "d+" : this.getDate(),                    //日
        "h+" : this.getHours(),                   //小时
        "m+" : this.getMinutes(),                 //分
        "s+" : this.getSeconds(),                 //秒
        "q+" : Math.floor((this.getMonth()+3)/3), //季度
        "S"  : this.getMilliseconds()             //毫秒
    };
    if(/(y+)/.test(fmt))
        fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
    for(var k in o)
        if(new RegExp("("+ k +")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
    return fmt;
}

function getRandomNum(Min,Max)
{
    var Range = Max - Min;
    var Rand = Math.random();
    return(Min + Math.round(Rand * Range));
}

/**
 * 吐司
 * @type
 * */
var toast = {
    c:function(tag){
        return document.createElement(tag);// 创建标签
    },
    bgColor:"#59B9C6",
    color:"white",
    fontSize:45,
    initFlag:false, //初始化
    toast:null,
    td:null,
    showTime:3000,
    showFlag:false,
    timeoutKey:null,
    widthPercent:0.8, //宽度占用比例为80%
    local:{x:0, y:0, width:540, height:120},
    tableHeight:60,
    contentTable:null,
    pagePercent:0.6,
    radius:5,
    top:99999999999999,
    init:function(){
        var p = this.c("div");
        var ww = document.body.clientWidth;//获取屏幕宽度
        if(ww>0){
            this.local.width = Math.ceil( ww * this.widthPercent );
        }
        //设置样式
        p.style.width = this.local.width + "px";
        p.style.position = "absolute";
        p.style.zIndex = this.top; //置于顶层
        p.style.textAlign = "center";
        p.style.verticalAlign = "middle";
        p.style.backgroundColor = this.bgColor;  // 灰色背景
        //p.style.opacity = 0.8;
        p.style.borderRadius = this.radius + "px";
        this.toast = p;
        this.initFlag = true;
        // 设置内容
        this.initContent();
    },
    setPercent:function(percent){
        var increase = percent / this.pagePercent;
        var fontSize = '20px';//Math.ceil(this.fontSize / increase);
        this.local.height = Math.ceil(this.tableHeight / increase);
        this.toast.style.height = this.local.height + "px";
        this.td.style.fontSize = fontSize + "px";
        this.contentTable.style.height = this.local.height + "px";
    },
    initContent:function(){
        var t = this.c("table");
        t.style.width = this.local.width + "px";
        t.style.height = this.local.height + "px";
        t.align = "center";
        var b = this.c("tbody");
        var tr = this.c("tr");
        this.td = this.c("td");
        this.td.style.textAlign = "center";
        this.td.style.verticalAlign = "middle";
        this.td.style.color = this.color;
        tr.appendChild(this.td);
        b.appendChild(tr);
        t.appendChild(b);
        this.toast.appendChild(t);
        this.contentTable = t;
    },
    initLocation:function(){
        var scrollTop = document.body.scrollTop;   // 当前滚动条的竖直滚动位置
        var scrollLeft = document.body.scrollLeft;  // 当前滚动条的水平滚动位置
        var width = document.body.clientWidth;  // 当前屏幕的宽度
        var height = document.documentElement.clientHeight ;  // 当前屏幕的高度
        // 计算居中位置
        this.local.x = Math.ceil((width - this.local.width)/2) + scrollLeft;
        this.local.y = Math.ceil((height - this.local.height)/2) + scrollTop;
    },
    show:function(value, percent){
        if(!value) return;
        if(!this.initFlag){
            this.init();
        }
        //设置比例
        if(typeof percent==="number") {
            this.setPercent(percent);
        }else{
            this.setPercent(this.pagePercent);
        }
        //初始化当前位置
        this.initLocation();
        this.toast.style.left = this.local.x + "px";
        this.toast.style.top = this.local.y + "px";
        this.toast.style.zIndex = this.top;
        this.td.innerHTML = value;
        // 判断当前是否早show
        if(this.showFlag){
            window.clearTimeout(this.timeoutKey);
        }else{
            document.body.appendChild(this.toast);
        }
        this.timeoutKey = window.setTimeout(this.hidden, this.showTime);
        this.showFlag = true;
    },
    hidden:function(){
        var me = toast;
        if(me.initFlag){
            window.clearTimeout(me.timeoutKey);// 不管如何消失, 都执行取消定时消失
            me.td.innerHTML = "";
            document.body.removeChild(me.toast);
            me.showFlag = false;
        }
    }
};


Date.prototype.myFormat = function(param)
{ //author: meizz
    var format = '',
        newDate;
    var date=this;
    if(!date) {
        return;
    } else {
        try {
            newDate = new Date(date);
        } catch(e) {
            console.log(e);
            return;
        }
    }

    //24小时内显示小时或分钟数，反
    var diff = (new Date().getTime()-newDate.getTime())/(1000*60);
    if(diff < 60) {
        format = parseInt(diff) + "分钟前";
    } else if(diff>=60 && diff < 60*24) {
        format = parseInt(diff/60) + "小时前";
    } else if(diff >= 60*24 && diff<60*24*7) {
        format = parseInt(diff/60/24) + "天前";//"1天前";
    } else {
        var year = newDate.getFullYear(),
            month  = newDate.getMonth()+1,
            day = newDate.getDate(),
            paddedMonth = month>9 ? month : '0'+month,
            paddedDay = day>9 ? day : '0'+day;

        switch(param) {
            case 'yyyy-MM-dd' :
                format = year +'-'+ paddedMonth +'-'+ paddedDay;
                break;
            case 'yyyy-M-dd' :
                format = year +'-'+ month +'-'+ paddedDay;
                break;
            case 'yyyy-MM-d' :
                format = year +'-'+ paddedMonth +'-'+ day;
                break;
            case 'yyyy-M-d' :
                format = year +'-'+ month +'-'+ day;
                break;
            default:
                format = year +'-'+ paddedMonth +'-'+ paddedDay;
                break;
        }
    }

    return format;
    return fmt;
}

/**
 * 点在面内方法
 * @param p
 * @param pl
 * @returns {boolean}
 */
function pointIsInPolygon(p,pl){
    var inside = false,
        part, p1, p2, i, j, k, len, len2;
    for (i = 0, len = pl._latlngs.length; i < len; i++) {
        part = pl._latlngs[i];
        for (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {
            p1 = part[j];
            p2 = part[k];
            if (((p1.lat > p.y) !== (p2.lat > p.y)) && (p.x < (p2.lng - p1.lng) * (p.y - p1.lat) / (p2.lat - p1.lat) + p1.lng)) {
                inside = !inside;
            }
        }
    }
    return inside;
}

var DATEFACTORY = {
    isinit: false,
    init: function () {
        now = new Date();                    //当前日期
        nowDayOfWeek = now.getDay();         //今天本周的第几天
        nowDay = now.getDate();              //当前日
        nowMonth = now.getMonth();           //当前月
        nowYear = now.getYear();             //当前年
        nowYear += (nowYear < 2000) ? 1900 : 0;  //
        DATEFACTORY.isinit = true;
    },
    //获得某月的天数
    getMonthDays: function (myMonth){
        var monthStartDate = new Date(nowYear, myMonth? myMonth: nowMonth, 1);
        var monthEndDate = new Date(nowYear, (myMonth? myMonth: nowMonth) + 1, 1);
        var days   =   (monthEndDate   -   monthStartDate)/(1000   *   60   *   60   *   24);
        return days;
    },
//获得本季度的开始月份
    getQuarterStartMonth: function (){
        var quarterStartMonth = 0;
        if(nowMonth<3){
            quarterStartMonth = 0;
        }
        if(2<nowMonth && nowMonth<6){
            quarterStartMonth = 3;
        }
        if(5<nowMonth && nowMonth<9){
            quarterStartMonth = 6;
        }
        if(nowMonth>8){
            quarterStartMonth = 9;
        }
        return quarterStartMonth;
    },
    //获得本周的开始日期
    getWeekStartDate: function () {
        var weekStartDate = /*new Date(*/new Date(nowYear, nowMonth, nowDay - nowDayOfWeek + 1 - (nowDayOfWeek==0?7:0))/*.getTime()+(24*60*60*1000))*/;
        //console.log(weekStartDate);
        return weekStartDate.Format('yyyy-MM-dd');
    },

    //获得本周的结束日期
    getWeekEndDate: function () {
        var weekEndDate = /*new Date(*/new Date(nowYear, nowMonth, nowDay + (6 - nowDayOfWeek +2) - (nowDayOfWeek==0?7:0))/*.getTime()+(24*60*60*1000))*/;
        //console.log(weekEndDate)
        return weekEndDate.Format('yyyy-MM-dd');
    },

    //获得本月的开始日期
    getMonthStartDate: function (){
        var monthStartDate = new Date(nowYear, nowMonth, 1);
        return monthStartDate.Format('yyyy-MM-dd');
    },

    //获得本月的结束日期
    getMonthEndDate: function (){
        var monthEndDate = new Date(nowYear, nowMonth, DATEFACTORY.getMonthDays(nowMonth)+1);
        return monthEndDate.Format('yyyy-MM-dd');
    },

    //获得本季度的开始日期
    getQuarterStartDate: function (){

        var quarterStartDate = new Date(nowYear, DATEFACTORY.getQuarterStartMonth(), 1);
        return quarterStartDate.Format('yyyy-MM-dd');
    },

    //或的本季度的结束日期
    getQuarterEndDate: function (){
        var quarterEndMonth = DATEFACTORY.getQuarterStartMonth() + 2;
        var quarterStartDate = new Date(nowYear, quarterEndMonth, DATEFACTORY.getMonthDays(quarterEndMonth)+1);
        return quarterStartDate.Format('yyyy-MM-dd');
    }
}



/*
 *  方法:Array.remove(dx) 通过遍历,重构数组
 *  功能:删除数组元素.
 *  参数:dx删除元素的下标.
 */
Array.prototype.remove=function(dx)
{
    if(isNaN(dx)||dx>this.length){return false;}
    for(var i=0,n=0;i<this.length;i++)
    {
        if(this[i]!=this[dx])
        {
            this[n++]=this[i]
        }
    }
    this.length-=1
}


function HashMap(){
    //定义长度
    var length = 0;
    //创建一个对象
    var obj = new Object();

    /**
     * 判断Map是否为空
     */
    this.isEmpty = function(){
        return length == 0;
    };

    /**
     * 判断对象中是否包含给定Key
     */
    this.containsKey=function(key){
        return (key in obj);
    };

    /**
     * 判断对象中是否包含给定的Value
     */
    this.containsValue=function(value){
        for(var key in obj){
            if(obj[key] == value){
                return true;
            }
        }
        return false;
    };

    /**
     *向map中添加数据
     */
    this.put=function(key,value){
        if(!this.containsKey(key)){
            length++;
        }
        obj[key] = value;
    };

    /**
     * 根据给定的Key获得Value
     */
    this.get=function(key){
        return this.containsKey(key)?obj[key]:null;
    };

    /**
     * 根据给定的Key删除一个值
     */
    this.remove=function(key){
        if(this.containsKey(key)&&(delete obj[key])){
            length--;
        }
    };

    /**
     * 获得Map中的所有Value
     */
    this.values=function(){
        var _values= new Array();
        for(var key in obj){
            _values.push(obj[key]);
        }
        return _values;
    };

    /**
     * 获得Map中的所有Key
     */
    this.keySet=function(){
        var _keys = new Array();
        for(var key in obj){
            _keys.push(key);
        }
        return _keys;
    };

    /**
     * 获得Map的长度
     */
    this.size = function(){
        return length;
    };

    /**
     * 清空Map
     */
    this.clear = function(){
        length = 0;
        obj = new Object();
    };
}



var DEF_PI = 3.14159265359; // PI
var DEF_2PI= 6.28318530712; // 2*PI
var DEF_PI180= 0.01745329252; // PI/180.0
var DEF_R =6378137; // radius of earth
function getdistance(lon1,lat1,lon2,lat2){
    var ew1, ns1, ew2, ns2;
    var dx, dy, dew;
    var distance;
    // 角度转换为弧度
    ew1 = lon1 * DEF_PI180;
    ns1 = lat1 * DEF_PI180;
    ew2 = lon2 * DEF_PI180;
    ns2 = lat2 * DEF_PI180;
    // 经度差
    dew = ew1 - ew2;
    // 若跨东经和西经180 度，进行调整
    if (dew > DEF_PI)
        dew = DEF_2PI - dew;
    else if (dew < -DEF_PI)
        dew = DEF_2PI + dew;
    dx = DEF_R * Math.cos(ns1) * dew; // 东西方向长度(在纬度圈上的投影长度)
    dy = DEF_R * (ns1 - ns2); // 南北方向长度(在经度圈上的投影长度)
    // 勾股定理求斜边长
    distance = Math.sqrt(dx * dx + dy * dy);
    return distance;
}


function getdistance1( lng1,lat1,lng2,lat2)
{

    var radLat1 = Rad(lat1);
    var radLng1 = Rad(lng1);
    var radLat2 = Rad(lat2);
    var radLng2 = Rad(lng2);
    var a = radLat1 - radLat2;
    var b = radLng1 - radLng2;
    var result = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2))) * DEF_R;
    return result;
}
/// <summary>
/// 经纬度转化成弧度
/// </summary>
/// <param name="d"></param>
/// <returns></returns>j
function Rad( d)
{
    return d * Math.PI / 180;
}

/**
 * 计算点到线的距离
 * @param px
 * @param py
 * @param lonlats
 */
function getPointTOPolyline(px,py,lines){
    var len=-1;
    var points=[];
    var zindexi=0;
    var zindexj=0;
    for(var i=0;i<lines.length;i++){
        var lonlats = lines[i].replace("LINESTRING (", "").replace(")", "").split(",");
        var coornates = [];
        for (var n = 0; n < lonlats.length; n++) {
            var ii = lonlats[n].replace(/(^\s*)|(\s*$)/g, '').split(" ")
            coornates.push([parseFloat(ii[1]), parseFloat(ii[0])])
        }

        for(var j=1;j<coornates.length;j++){
           var l= PointToSegDist(px,py,coornates[j-1][1],coornates[j-1][0],coornates[j][1],coornates[j][0]);
            if(len==-1||len>l){
                len=l;
                points=[coornates[j-1][1],coornates[j-1][0],coornates[j][1],coornates[j][0]];
                zindexi=i;
                zindexj=j;
            }
        }
    }

    //求一个点到另
    //var otherlen=lineSpace(px,py,points[0],points[1]);
    //var lastlen=lineSpace(points[0],points[1],points[2],points[3]);
    //var tmplen=Math.sqrt( Math.abs(Math.pow(otherlen,2) -Math.pow(len,2)))
    //
    //var llastlen=lineSpace(px,py,points[2],points[3]);
    //var tmp2len=Math.sqrt( Math.abs(Math.pow(llastlen,2) -Math.pow(len,2)))
    //console.log(tmp2len+tmplen,lastlen)
    //var bl=tmplen/lastlen;
    var dulon=points[0]+(points[2]-points[0])/2;
    var dulat=points[1]+(points[3]-points[1])/2;

    return {
        len:getdistance(px,py,dulon,dulat),
        //lenA:getdistance(points[0],points[1],dulon,dulat),
        //lenB:getdistance(points[2],points[3],dulon,dulat),
        lon:dulon,
        lat:dulat,
        zindexi:zindexi,
        zindexj:zindexj,
        points:points
    };
}


//经纬度转墨卡托
function lonlat2mercator(lonlat){
    var  mercator={x:0,y:0};
    var x = lonlat.x *20037508.34/180;
    var y = Math.log(Math.tan((90+lonlat.y)*Math.PI/360))/(Math.PI/180);
    y = y *20037508.34/180;
    mercator.x = x;
    mercator.y = y;
    return mercator ;
}
function PointToSegDist( x,  y,  x1,  y1,  x2,  y2)
{
    //var lonlat1=lonlat2mercator({x:x,y:y});
    //var lonlat2= lonlat2mercator({x:parseFloat(x1),y:parseFloat(y1)});
    //var lonlat3=lonlat2mercator({x:parseFloat(x2),y:parseFloat(y2)});
    //
    //x=lonlat1.x;
    //y=lonlat1.y;
    //x1=lonlat2.x;
    //y1=lonlat2.y;
    //x2=lonlat3.x;
    //y2=lonlat3.y;

    var cross = (x2 - x1) * (x - x1) + (y2 - y1) * (y - y1);
    if (cross <= 0) return  Math.sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));

    var d2 = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
    if (cross >= d2) return  Math.sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2));

    var r = cross / d2;
    var px = x1 + (x2 - x1) * r;
    var py = y1 + (y2 - y1) * r;
    return Math.sqrt((x-px)*(x-px)+(py-y)*(py-y))
}



// 点到直线的最短距离的判断 点（x0,y0） 到由两点组成的线段（x1,y1） ,( x2,y2 )

function   pointToLine(x0,y0, x1,  y1,  x2,  y2) {

    var space = 0;

    var a, b, c;

    a = getdistance(x1, y1, x2, y2);// 线段的长度

    b = getdistance(x1, y1, x0, y0);// (x1,y1)到点的距离

    c = getdistance(x2, y2, x0, y0);// (x2,y2)到点的距离

    if (c+b == a) {//点在线段上

        space = 0;

        return space;

    }

    if (a <= 0.000001) {//不是线段，是一个点

        space = b;

        return space;

    }

    if (c * c >= a * a + b * b) { //组成直角三角形或钝角三角形，(x1,y1)为直角或钝角

        space = b;

        return space;

    }

    if (b * b >= a * a + c * c) {//组成直角三角形或钝角三角形，(x2,y2)为直角或钝角

        space = c;

        return space;

    }
    //组成锐角三角形，则求三角形的高
    var p = (a + b + c) / 2;// 半周长

    var s = Math.sqrt(p * (p - a) * (p - b) * (p - c));// 海伦公式求面积

    space = 2 * s / a;// 返回点到线的距离（利用三角形面积公式求高）

    return space;

}

Array.prototype.baoremove = function(dx)
{ // www.jb51.net
    if(isNaN(dx)||dx>this.length){return false;}
    this.splice(dx,1);
}
// 计算两点之间的距离

function   lineSpace( x1,  y1,  x2,  y2) {

    var  lineLength = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2)* (y1 - y2));

    return lineLength;
}




var GPS = {
    PI : 3.14159265358979324,
    x_pi : 3.14159265358979324 * 3000.0 / 180.0,
    delta : function (lat, lon) {
        // Krasovsky 1940
        //
        // a = 6378245.0, 1/f = 298.3
        // b = a * (1 - f)
        // ee = (a^2 - b^2) / a^2;
        var a = 6378245.0; //  a: 卫星椭球坐标投影到平面地图坐标系的投影因子。
        var ee = 0.00669342162296594323; //  ee: 椭球的偏心率。
        var dLat = this.transformLat(lon - 105.0, lat - 35.0);
        var dLon = this.transformLon(lon - 105.0, lat - 35.0);
        var radLat = lat / 180.0 * this.PI;
        var magic = Math.sin(radLat);
        magic = 1 - ee * magic * magic;
        var sqrtMagic = Math.sqrt(magic);
        dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * this.PI);
        dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * this.PI);
        return {'lat': dLat, 'lon': dLon};
    },

    //WGS-84 to GCJ-02
    gcj_encrypt : function (wgsLat, wgsLon) {
        if (this.outOfChina(wgsLat, wgsLon))
            return {'lat': wgsLat, 'lon': wgsLon};

        var d = this.delta(wgsLat, wgsLon);
        return {'lat' : wgsLat + d.lat,'lon' : wgsLon + d.lon};
    },
    //GCJ-02 to WGS-84
    gcj_decrypt : function (gcjLat, gcjLon) {
        if (this.outOfChina(gcjLat, gcjLon))
            return {'lat': gcjLat, 'lon': gcjLon};

        var d = this.delta(gcjLat, gcjLon);
        return {'lat': gcjLat - d.lat, 'lon': gcjLon - d.lon};
    },
    //GCJ-02 to WGS-84 exactly
    gcj_decrypt_exact : function (gcjLat, gcjLon) {
        var initDelta = 0.01;
        var threshold = 0.000000001;
        var dLat = initDelta, dLon = initDelta;
        var mLat = gcjLat - dLat, mLon = gcjLon - dLon;
        var pLat = gcjLat + dLat, pLon = gcjLon + dLon;
        var wgsLat, wgsLon, i = 0;
        while (1) {
            wgsLat = (mLat + pLat) / 2;
            wgsLon = (mLon + pLon) / 2;
            var tmp = this.gcj_encrypt(wgsLat, wgsLon)
            dLat = tmp.lat - gcjLat;
            dLon = tmp.lon - gcjLon;
            if ((Math.abs(dLat) < threshold) && (Math.abs(dLon) < threshold))
                break;

            if (dLat > 0) pLat = wgsLat; else mLat = wgsLat;
            if (dLon > 0) pLon = wgsLon; else mLon = wgsLon;

            if (++i > 10000) break;
        }
        //console.log(i);
        return {'lat': wgsLat, 'lon': wgsLon};
    },
    //GCJ-02 to BD-09
    bd_encrypt : function (gcjLat, gcjLon) {
        var x = gcjLon, y = gcjLat;
        var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * this.x_pi);
        var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * this.x_pi);
        bdLon = z * Math.cos(theta) + 0.0065;
        bdLat = z * Math.sin(theta) + 0.006;
        return {'lat' : bdLat,'lon' : bdLon};
    },
    //BD-09 to GCJ-02
    bd_decrypt : function (bdLat, bdLon) {
        var x = bdLon - 0.0065, y = bdLat - 0.006;
        var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * this.x_pi);
        var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * this.x_pi);
        var gcjLon = z * Math.cos(theta);
        var gcjLat = z * Math.sin(theta);
        return {'lat' : gcjLat, 'lon' : gcjLon};
    },
    //WGS-84 to Web mercator
    //mercatorLat -> y mercatorLon -> x
    mercator_encrypt : function(wgsLat, wgsLon) {
        var x = wgsLon * 20037508.34 / 180.;
        var y = Math.log(Math.tan((90. + wgsLat) * this.PI / 360.)) / (this.PI / 180.);
        y = y * 20037508.34 / 180.;
        return {'lat' : y, 'lon' : x};
        /*
         if ((Math.abs(wgsLon) > 180 || Math.abs(wgsLat) > 90))
         return null;
         var x = 6378137.0 * wgsLon * 0.017453292519943295;
         var a = wgsLat * 0.017453292519943295;
         var y = 3189068.5 * Math.log((1.0 + Math.sin(a)) / (1.0 - Math.sin(a)));
         return {'lat' : y, 'lon' : x};
         //*/
    },
    // Web mercator to WGS-84
    // mercatorLat -> y mercatorLon -> x
    mercator_decrypt : function(mercatorLat, mercatorLon) {
        var x = mercatorLon / 20037508.34 * 180.;
        var y = mercatorLat / 20037508.34 * 180.;
        y = 180 / this.PI * (2 * Math.atan(Math.exp(y * this.PI / 180.)) - this.PI / 2);
        return {'lat' : y, 'lon' : x};
        /*
         if (Math.abs(mercatorLon) < 180 && Math.abs(mercatorLat) < 90)
         return null;
         if ((Math.abs(mercatorLon) > 20037508.3427892) || (Math.abs(mercatorLat) > 20037508.3427892))
         return null;
         var a = mercatorLon / 6378137.0 * 57.295779513082323;
         var x = a - (Math.floor(((a + 180.0) / 360.0)) * 360.0);
         var y = (1.5707963267948966 - (2.0 * Math.atan(Math.exp((-1.0 * mercatorLat) / 6378137.0)))) * 57.295779513082323;
         return {'lat' : y, 'lon' : x};
         //*/
    },
    // two point's distance
    distance : function (latA, lonA, latB, lonB) {
        var earthR = 6371000.;
        var x = Math.cos(latA * this.PI / 180.) * Math.cos(latB * this.PI / 180.) * Math.cos((lonA - lonB) * this.PI / 180);
        var y = Math.sin(latA * this.PI / 180.) * Math.sin(latB * this.PI / 180.);
        var s = x + y;
        if (s > 1) s = 1;
        if (s < -1) s = -1;
        var alpha = Math.acos(s);
        var distance = alpha * earthR;
        return distance;
    },
    outOfChina : function (lat, lon) {
        if (lon < 72.004 || lon > 137.8347)
            return true;
        if (lat < 0.8293 || lat > 55.8271)
            return true;
        return false;
    },
    transformLat : function (x, y) {
        var ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
        ret += (20.0 * Math.sin(6.0 * x * this.PI) + 20.0 * Math.sin(2.0 * x * this.PI)) * 2.0 / 3.0;
        ret += (20.0 * Math.sin(y * this.PI) + 40.0 * Math.sin(y / 3.0 * this.PI)) * 2.0 / 3.0;
        ret += (160.0 * Math.sin(y / 12.0 * this.PI) + 320 * Math.sin(y * this.PI / 30.0)) * 2.0 / 3.0;
        return ret;
    },
    transformLon : function (x, y) {
        var ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
        ret += (20.0 * Math.sin(6.0 * x * this.PI) + 20.0 * Math.sin(2.0 * x * this.PI)) * 2.0 / 3.0;
        ret += (20.0 * Math.sin(x * this.PI) + 40.0 * Math.sin(x / 3.0 * this.PI)) * 2.0 / 3.0;
        ret += (150.0 * Math.sin(x / 12.0 * this.PI) + 300.0 * Math.sin(x / 30.0 * this.PI)) * 2.0 / 3.0;
        return ret;
    }
};


function utilgetLocation(callback){
    //var geolocation = new qq.maps.Geolocation();
    //var u = navigator.userAgent;
    //if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {//安卓手机
    //    var options = {timeout: 9000};
    //    function getCurLocation(callback) {
    //        geolocation.getLocation(function(position){
    //            var position= GPS.gcj_decrypt(position.lat,position.lng);
    //            callback(position.lon,position.lat);
    //        }, showErr, options);
    //    }
    //    function showErr() {
    //        toast.show("定位失败")
    //    };
    //    getCurLocation(callback);
    //} else if (u.indexOf('iPhone') > -1) {//苹果手机
        islocal=true;

       if(bowerclient=='alipay'){
           ap.getLocation(function(res) {
              //JSON.stringify(res);
               if(res.error){
                   ap.showToast(res.errorMessage);
               }else{
                   var latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
                   var longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。
                   //map.setView(new L.LatLng(latitude,longitude),map.getZoom());
                   islocal=false;
                   callback(longitude,latitude)
               }
           });
       }else{
           wx.getLocation({
               type: "wgs84", // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
               success: function (res) {
                   var latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
                   var longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。
                   //map.setView(new L.LatLng(latitude,longitude),map.getZoom());
                   islocal=false;
                   callback(longitude,latitude)
               } ,
               fail:function(e){
                   //toast.show("请您在打开设备的GPS模块，才能定位哦！！！")
               }
           })
       }

    //} else if (u.indexOf('Windows Phone') > -1) {//winphone手机
    //    toast.show("暂不支持！")
    //}
}
/**
 * 合并多条线为一条
 * @param polylines
 */
function unionline(startpoint,polylines){
    var allline=[];
    //var hashmap=new HashMap();
    ////去重
    //for(var i=0;i<polylines.length;i++){
    //    if(!hashmap.containsKey(polylines[i]._latlngs.toString())){
    //        hashmap.put(polylines[i]._latlngs.toString(),polylines[i]);
    //    }
    //}
    //var polylines=hashmap.values();
    for(var index=0;index<polylines.length;index++){
        //if(polylines[index]._latlngs[0] instanceof L.LatLng){
        //    polylines[index]._latlngs[0]=polylines[index]._latlngs
        //}
        for(var j=0;j<polylines[index]._latlngs.length;j++)
        {
            var lonlats=polylines[index]._latlngs[j];
            if(lonlats[0].lng==startpoint.lng&&lonlats[0].lat==startpoint.lat){
                //方向正确
                allline= allline.concat()
            }
            if(lonlats[lonlats.length-1].lng==startpoint.lng&&lonlats[lonlats.length-1].lat==startpoint.lat){
                //方向相反
                allline=allline.concat(lonlats)
            }
            startpoint=lonlats[lonlats.length-1];
            break;
        }
        //if(startpoint.lon=polylines[index])
    }
    var f=[];
    for(var i=0;i<polylines.length;i++){
        for(var j=0;j<polylines[i]._latlngs.length;j++) {
            for(var m=0;m<polylines[i]._latlngs[j].length;m++)
            f.push([polylines[i]._latlngs[j][m].lat, polylines[i]._latlngs[j][m].lng])
        }
    }
    return f;
}

